<!--<link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">-->
<link rel="stylesheet" href="lib/jq-module/zyupload/zyupload-1.0.0.min.css" media="all">
<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
        <blockquote class="layui-elem-quote">
            这里是一个系统通知，可在后台进行设定
        </blockquote>
        <form class="layui-form" action="">
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                <legend>相册信息</legend>
            </fieldset>
            <div class="layui-form-item">
                <label class="layui-form-label">标题</label>
                <div class="layui-input-inline">
                    <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入相册标题"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">简介</label>
                <div class="layui-input-block">
                    <textarea name="describe" autocomplete="off" placeholder="请输入相册简介" class="layui-input"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否公开</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="isPublic" lay-skin="switch" lay-text="是|否">
                </div>
            </div>
            <center>
                <button class="layui-btn number-of-people-btn" lay-submit="" lay-filter="save">保存</button>
            </center>
        </form>
    </div>
</div>
<script src="lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="lib/jq-module/zyupload/zyupload-1.0.0.min.js" charset="utf-8"></script>
<script type="text/javascript">
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length < 5) {
                    return '至少得5个字符啊';
                }
            }
            , pass: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ]
            , content: function (value) {
                layedit.sync(editIndex);
            }
        });

        //监听指定开关
        form.on('switch(switchTest)', function (data) {
            layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });

        //监听提交
        form.on('submit(save)', function (data) {
            var isPub=true;
            if(data.field.isPublic==='off'){
                isPub=false;
            }
            jq1111.ajax({
                type: "POST",
                crossDomain:true,
                url: BasePath+"api/SchoolAlbum/Add",
                contentType: "application/json",
                dataType:"json",
                xhrFields: {
                    withCredentials: true
                },
                data:JSON.stringify({
                    "title": data.field.title,
                    "description": data.field.describe,
                    "isPublic": isPub
                }),
                success:function (message) {
                    console.log(message);
                    layer.alert(message.msg, {
                        title: '操作结果'
                    })
                    location.reload()
                },
                error:function (message) {
                    console.log(message.responseJSON);
                    layer.alert(message.responseJSON.msg, {
                        title: '操作结果'
                    })
                },
            });

            return false;
        });
    });
</script>